package io.renren.modules.archive.service.impl;

import io.renren.common.utils.DateUtils;
import io.renren.common.utils.ExportUtils;
import io.renren.modules.archive.entity.ArchiveAttachEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.archive.dao.ArchiveInfoDao;
import io.renren.modules.archive.entity.ArchiveInfoEntity;
import io.renren.modules.archive.service.ArchiveInfoService;


@Service("archiveInfoService")
public class ArchiveInfoServiceImpl extends ServiceImpl<ArchiveInfoDao, ArchiveInfoEntity> implements ArchiveInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //根据文件名称查询
        String value = (String)params.get("key");
        String search = (String)params.get("search");
        IPage<ArchiveInfoEntity> page = this.page(
                new Query<ArchiveInfoEntity>().getPage(params),
                new QueryWrapper<ArchiveInfoEntity>().like(StringUtils.isNotBlank(value),search, value)
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils conditionQueryPage(Map<String, Object> params) {
        //根据文件名称查询
        String attachId  = (String)params.get("attachId");
        String nd  = (String)params.get("nd");
        String title  = (String)params.get("title");
        String author  = (String)params.get("author");
        String  startrq = (String)params.get("startrq");
        String  stoprq = (String)params.get("stoprq");
        String wh  = (String)params.get("wh");
        String qzh  = (String)params.get("qzh");
        String dh  = (String)params.get("dh");
        String jg  = (String)params.get("jg");
        String bgqx  = (String)params.get("bgqx");
        String unitno  = (String)params.get("unitno");
        String damldm  = (String)params.get("damldm");
        String ngdw  = (String)params.get("ngdw");
        String wz  = (String)params.get("wz");
        String ngr  = (String)params.get("ngr");
        String bksm  = (String)params.get("bksm");
        String mlh  = (String)params.get("mlh");
        String zbkwh  = (String)params.get("zbkwh");
        String hhd  = (String)params.get("hhd");
        String dalx  = (String)params.get("dalx");
        String ys  = (String)params.get("ys");
        String mj  = (String)params.get("mj");
        String hh  = (String)params.get("hh");
        String flh  = (String)params.get("flh");
        String bz  = (String)params.get("bz");
        String zlcj  = (String)params.get("zlcj");
        String fwhty  = (String)params.get("fwhty");
        String xhqk  = (String)params.get("xhqk");
        String kfbs  = (String)params.get("kfbs");
        String gksx  = (String)params.get("gksx");
        String gjc  = (String)params.get("gjc");
        IPage<ArchiveInfoEntity> page = this.page(
                new Query<ArchiveInfoEntity>().getPage(params),
                new QueryWrapper<ArchiveInfoEntity>()
                        .like(StringUtils.isNotBlank(attachId),"attach_id", attachId)
                        .like(StringUtils.isNotBlank(nd),"nd", nd)
                        .like(StringUtils.isNotBlank(title),"title", title)
                        .like(StringUtils.isNotBlank(author),"author", author)
                        .apply(StringUtils.isNotBlank(startrq),"rq >= to_date('" +startrq  + "','yyyy-MM-dd')")
                        .apply(StringUtils.isNotBlank(stoprq),"rq <= to_date('" +stoprq  + "','yyyy-MM-dd')")
                        .like(StringUtils.isNotBlank(wh),"wh", wh)
                        .like(StringUtils.isNotBlank(qzh),"qzh", qzh)
                        .like(StringUtils.isNotBlank(dh),"dh", dh)
                        .like(StringUtils.isNotBlank(jg),"jg", jg)
                        .like(StringUtils.isNotBlank(bgqx),"bgqx", bgqx)
                        .like(StringUtils.isNotBlank(unitno),"unitno", unitno)
                        .like(StringUtils.isNotBlank(damldm),"damldm", damldm)
                        .like(StringUtils.isNotBlank(ngdw),"ngdw", ngdw)
                        .like(StringUtils.isNotBlank(wz),"wz", wz)
                        .like(StringUtils.isNotBlank(ngr),"ngr", ngr)
                        .like(StringUtils.isNotBlank(bksm),"bksm", bksm)
                        .like(StringUtils.isNotBlank(mlh),"mlh", mlh)
                        .like(StringUtils.isNotBlank(zbkwh),"zbkwh", zbkwh)
                        .like(StringUtils.isNotBlank(hhd),"hhd", hhd)
                        .like(StringUtils.isNotBlank(dalx),"dalx", dalx)
                        .like(StringUtils.isNotBlank(ys),"ys", ys)
                        .like(StringUtils.isNotBlank(mj),"mj", mj)
                        .like(StringUtils.isNotBlank(hh),"hh", hh)
                        .like(StringUtils.isNotBlank(flh),"flh", flh)
                        .like(StringUtils.isNotBlank(bz),"bz", bz)
                        .like(StringUtils.isNotBlank(zlcj),"zlcj", zlcj)
                        .like(StringUtils.isNotBlank(fwhty),"fwhty", fwhty)
                        .like(StringUtils.isNotBlank(xhqk),"xhqk", xhqk)
                        .like(StringUtils.isNotBlank(kfbs),"kfbs", kfbs)
                        .like(StringUtils.isNotBlank(gksx),"gksx", gksx)
                        .like(StringUtils.isNotBlank(gjc),"gjc", gjc)
        );

        return new PageUtils(page);
    }

}